package com.jess.arms.base.app;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Handler;

import com.elvishew.xlog.XLog;

import java.util.WeakHashMap;


/*
 * created by liuyang on 2018/9/4
 */
public final class Quick {
    private static final WeakHashMap<Object, Object> QUICK_CONFIGS = new WeakHashMap<>();
    public static void init(Context context) {

        QUICK_CONFIGS.put(ConfigKeys.APPLICATION_CONTEXT,context);
       
    }
    public static void withConfigure(Object key,Object value) {
        QUICK_CONFIGS.put(key,value);
    }
    public static void setDatas(){

    }
    public static Context getApplicationContext() {
        return getConfiguration(ConfigKeys.APPLICATION_CONTEXT);
    }

    public static String getToken() {
       return getConfiguration(ConfigKeys.TOKEN)==null?"":getConfiguration(ConfigKeys.TOKEN);
    }

    public static String getAppSessionId(){
        return getConfiguration(ConfigKeys.APP_SESSION_ID)==null?"":getConfiguration(ConfigKeys.APP_SESSION_ID);
    }
    public static <T> T getConfiguration(Object key) {
        T t = null;
        try {
            final Object value = QUICK_CONFIGS.get(key);
            if (value == null) {
                if(ConfigKeys.API_HOST.name().equals(key.toString())){
                    return null;
                }
                throw new NullPointerException(key.toString() + " IS NULL");
            }
            t = (T)QUICK_CONFIGS.get(key);
        } catch (Exception e) {
            XLog.e("获取配置信息出错",e);

        }finally {
            return  t;
        }


    }

    public static Handler getHandler() {
        return getConfiguration(ConfigKeys.HANDLER);
    }

}